﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
dbt = 'auction_userlastbid';
</cfscript>

<!---会员竞买记录总数--->
<cffunction name="mybidrecord" access="public" returntype="string">
<cfquery datasource="#DB#" name="mybidrecord">
SELECT
count(1) as rc
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
WHERE
uid = #uid# AND
auction.atag > 0
</cfquery>
<cfreturn mybidrecord.rc>
</cffunction>

<!---会员竞拍中总数--->
<cffunction access="public" name="userbuyerbidrecord" returntype="string">
<cfquery datasource="#DB#" name="userbuyerbidrecord">
SELECT
count(1) as rc
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
WHERE
auction_userlastbid.uid = #uid#
and auction_userlastbid.aid in (select aid from auction where asid in (select asid from auction_special where now() between asopentime and asclosetime) )
</cfquery>
<cfreturn userbuyerbidrecord.rc>

</cffunction>

<!---会员已得标总数--->
<cffunction access="public" name="userbuyerwonrecord" returntype="string">

<cfquery datasource="#DB#" name="userbuyerwonrecord">
SELECT
count(1) as rc
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
WHERE
auction_userlastbid.uid = #uid#
and auction_userlastbid.is_bid=1 and auction_userlastbid.aid in (select aid from auction where asid in (select asid from auction_special where now() > asclosetime) )
</cfquery>
<cfreturn userbuyerwonrecord.rc>

</cffunction>


<!---会员未得标总数--->
<cffunction access="public" name="userbuyerdontwinrecord" returntype="string">

<cfquery datasource="#DB#" name="userbuyerdontwinrecord">
SELECT
count(1) as rc
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
WHERE
auction_userlastbid.uid = #uid#
and auction_userlastbid.is_bid=0 and auction_userlastbid.aid in (select aid from auction where asid in (select asid from auction_special where now() > asclosetime) )
</cfquery>
<cfreturn userbuyerdontwinrecord.rc>

</cffunction>

<!---会员得标未加入交易的拍品--->
<cffunction access="public" name="userunintopaidrecord" returntype="string">
<cfquery datasource="#DB#" name="userunintopaidrecord">
SELECT
count(1) as rc
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
WHERE
auction_userlastbid.uid = #uid#
and auction_userlastbid.is_bid=1 and auction_userlastbid.pay_status=0  and auction_userlastbid.aid in (select aid from auction where asid in (select asid from auction_special where now() > asclosetime) )
</cfquery>
<cfreturn userunintopaidrecord.rc>

</cffunction>












<!---我的拍品最后出价--->
<cffunction name="myaidlastbid" access="public" returntype="query">
	<cfquery datasource="#DB#" name="myaidlastbid">
  SELECT bid
  FROM auction_userlastbid
  WHERE aid = #aid# AND uid = #session.user.uid# AND is_bid = 1
  </cfquery>
  <cfreturn myaidlastbid>
</cffunction>

<!---别人的拍品最后出价--->
<cffunction name="otheraidlastbid" access="public" returntype="query">
	<cfquery datasource="#DB#" name="otheraidlastbid">
  SELECT bid
  FROM auction_userlastbid
  WHERE aid = #aid# AND uid <> #session.user.uid# AND is_bid = 1
  </cfquery>
  <cfreturn otheraidlastbid>
</cffunction>

<!---是否有自己的出价记录--->
<cffunction name="checkuserlastbid" access="public" returntype="query">
	<cfquery datasource="#DB#" name="checkuserlastbid">
  select uid,bid,wonID
  from #dbt#
  where aid = #aid# and uid = #uid#
  </cfquery>
  <cfreturn checkuserlastbid>
</cffunction>

<!---会员竞拍中--->
<cffunction access="public" name="userbuyerbid" returntype="query">
	<!---根据UUID查找ID--->
  <cfinvoke component="app.cfc.user" method="uuidgetuid" returnvariable="uuidgetuid" UUID="#uuid#"/>
  <cfif uuidgetuid.recordcount neq 1>
  	<!---,"msg":"用户ID错误"--->
    <cfset j = {"success":"0","errCode":"0"}>
  <cfelse>
	<cfquery datasource="#DB#" name="userbuyerbid">
	SELECT
	 distinct 
	auction.aid,
	auction.acode,
	auction.auction,
	auction.lastprice,
	prevtime,starttime,
	auction.endtime,atag,
	auction_gallery.img_waterfall
	FROM
	auction_userlastbid
	INNER JOIN auction ON auction.aid = auction_userlastbid.aid
	INNER JOIN auction_gallery ON auction_gallery.agid = auction.agid
	WHERE
	auction_userlastbid.uid = #uuidgetuid.uid#
	and auction_userlastbid.aid in (select aid from auction where asid in (select asid from auction_special where now() between asopentime and asclosetime) )
	ORDER BY
	auction.endtime DESC
	</cfquery>
	<cfreturn userbuyerbid>
	</cfif>
</cffunction>
<!---得标--->
<cffunction access="remote" name="userwon" returntype="query">
<cfquery datasource="#DB#" name="userwon">
SELECT
auction.aid,
auction.acode,
auction.auction,
auction.lastprice,
auction_userlastbid.bid,
prevtime,starttime,
auction.endtime,
auction_userlastbid.is_bid,wonID,atag,
auction_gallery.img_waterfall
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
INNER JOIN auction_gallery ON auction_gallery.agid = auction.agid
WHERE
auction_userlastbid.uid = #uid#
AND is_bid = 1
AND atag > 0
AND endtime < #now()#
<cfif isdefined('attention')>
<cfswitch expression="#attention#">
<cfcase value="1">
AND auction.aid in (#mygzlist#)
</cfcase>
<cfcase value="0">
AND auction.aid not in (#mygzlist#)
</cfcase>
</cfswitch>
</cfif>
ORDER BY
auction.endtime DESC
</cfquery>
<cfreturn userwon>
</cffunction>

<!---未得标--->
<cffunction access="remote" name="userdontwin" returntype="query">
<cfquery datasource="#DB#" name="userdontwin">
SELECT
distinct 
auction.aid,
auction.acode,
auction.auction,
auction.lastprice,
prevtime,starttime,
auction.endtime,
auction_userlastbid.is_bid,atag,
auction_gallery.img_waterfall
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
INNER JOIN auction_gallery ON auction_gallery.agid = auction.agid
WHERE
auction_userlastbid.uid = #uid#
AND is_bid = 0
AND atag > 0
AND  endtime < #now()#
<cfif isdefined('attention')>
<cfswitch expression="#attention#">
<cfcase value="1">
AND auction.aid in (#mygzlist#)
</cfcase>
<cfcase value="0">
AND auction.aid not in (#mygzlist#)
</cfcase>
</cfswitch>
</cfif>
ORDER BY
auction.endtime DESC
</cfquery>
<cfreturn userdontwin>
</cffunction>

<!---得标未生成支付单--->
<cffunction access="remote" name="userwonunpay" returntype="query">
<cfquery datasource="#DB#" name="userwonunpay">
SELECT
auction.aid,
auction.acode,
auction.auction,
auction.pcid,
auction_userlastbid.bid,
auction.endtime,
auction_userlastbid.is_bid,
auction.lastprice,
auction.servicefee,
auction_gallery.img_waterfall
FROM
auction_userlastbid
INNER JOIN auction ON auction.aid = auction_userlastbid.aid
INNER JOIN auction_gallery ON auction_gallery.agid = auction.agid
WHERE
auction_userlastbid.uid = #uid#
AND auction_userlastbid.is_bid = 1
and auction_userlastbid.pay_status=0
and auction_userlastbid.aid in (select aid from auction where asid in (select asid from auction_special where now() > asclosetime)) 

ORDER BY
auction.endtime ASC
</cfquery>
<cfreturn userwonunpay>
</cffunction>




</cfcomponent>